package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.CouponBean;
import com.scoy.honeymei.bean.CouponBean0;
import com.scoy.honeymei.utils.TimeUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class CouponListAdapter0 extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<CouponBean0> datalist;
    private TextView notv;

    public CouponListAdapter0(Context context, ArrayList<CouponBean0> datalist, TextView notv) {
        this.context = context;
        this.datalist = datalist;
        this.notv = notv;
    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_ticket, parent, false);
        return new CouponHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        CouponHolder couponHolder = (CouponHolder) holder;
        CouponBean0 couponBean = datalist.get(position);
        couponHolder.ictPriceTv.setText(couponBean.getMoney());
        couponHolder.ictTitleTv.setText(couponBean.getType_name());
        couponHolder.ictValuedateTv.setText(TimeUtil.getLongToDatePHP(couponBean.getEndtime(), "yyyy-MM-dd"));
        couponHolder.ictFulluseTv.setText("满" + couponBean.getCondition() + "元可用");
        int usetype = couponBean.getUsetype();
        if (usetype == 1) {
            couponHolder.ictBtnTv.setBackgroundResource(R.drawable.shape_orange_all90);
            couponHolder.ictBtnTv.setText("未使用");
        } else if (usetype == 2) {
            couponHolder.ictBtnTv.setBackgroundResource(R.drawable.shape_gray_all90);
            couponHolder.ictBtnTv.setText("已使用");
        } else if (usetype == 3) {
            couponHolder.ictBtnTv.setBackgroundResource(R.drawable.shape_gray_all90);
            couponHolder.ictBtnTv.setText("已失效");
        }

        couponHolder.ictBtnTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onOneClick != null) {
                    onOneClick.oneClick(position);
                }
            }
        });


    }

    @Override
    public int getItemCount() {
        int iCount = datalist == null ? 0 : datalist.size();
        if (iCount == 0) {
            notv.setVisibility(View.VISIBLE);
        } else {
            notv.setVisibility(View.GONE);
        }
        return iCount;
    }


    class CouponHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.ict_fulluse_tv)
        TextView ictFulluseTv;
        @BindView(R.id.ict_price_tv)
        TextView ictPriceTv;
        @BindView(R.id.ict_left_cl)
        ConstraintLayout ictLeftCl;
        @BindView(R.id.ict_title_tv)
        TextView ictTitleTv;
        @BindView(R.id.ict_btn_tv)
        TextView ictBtnTv;
        @BindView(R.id.ict_valueadd_tv)
        TextView ictValueaddTv;
        @BindView(R.id.ict_valuedate_tv)
        TextView ictValuedateTv;
        @BindView(R.id.item_ticket)
        ConstraintLayout itemTicket;

        CouponHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
